﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DAWSharp.DSP.Dynamics
{
    /// <summary>
    /// DSP to apply a saturation effect based on http://tap-plugins.sourceforge.net/ladspa/sigmoid.html
    /// </summary>
    public class Saturation
    {
        /// <summary>
        /// Applies a saturation effect based on http://tap-plugins.sourceforge.net/ladspa/sigmoid.html
        /// </summary>
        /// <param name="input">Sample to process</param>
        /// <param name="gain">Gain to be applied</param>
        /// <returns>Processed sample</returns>
        public float Process(float input, float gain)
        {
            double preSat = input * gain;
            return (float)(2.0 / (1 + (Math.Pow(Math.E, (-5 * preSat)))) - 1.0);
        }
    }
}
